package com.aternity.httpfetch;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author Daniel Orr
 */
public class CleanEmptyLines {

    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("ip.list.csv");
        FileWriter fw = new FileWriter("outfile.txt");
        try (
                BufferedReader br = new BufferedReader(fr);
                BufferedWriter bw = new BufferedWriter(fw)) {
            String line;

            while ((line = br.readLine()) != null) {
                line = line.trim(); // remove leading and trailing whitespace
                int count = StringUtils.countMatches(line, ",");
                if (!line.equals("") || count == 4) // don't write out blank lines
                {
                    bw.write(line, 0, line.length());
                    bw.write('\n');
                }
            }
        }
    }
}
